<template>
  <div class="bubble-text" :class="direction">
    <template v-if="image != void 0 && direction == 'left'">
        <img :src="imgHttp+image" alt="" v-if="image">
        <img src="../../assets/images/default-photo.jpg" alt="" v-else>
      </template>
      <dl>
        <dd class="date">{{ date }}</dd>
        <dd class="text" v-html="text"></dd>
      </dl>
      <template v-if="image != void 0 && direction == 'right'">
        <img :src="imgHttp + image" alt="" v-if="image">
        <img src="../../assets/images/default-photo.jpg" alt="" v-else>
      </template>
  </div>
</template>

<script>
export default {
  name: 'bubble-text',
  props: {
    /**
     * 内容
     */
    text: {
      type: String
    },
    /**
     * 日期
     */
    date: {
      type: String
    },
    /**
     * 浮动
     */
    direction: {
      type: String,
      default: 'left'
    },
    /**
     * 图片
     */
    image: {
      type: String
    }
  },
  computed: {
    imgHttp() {
      return window.imgHttp;
    }
  }
};
</script>


<style lang="scss" scope>
  @import '../../assets/style/config';
  @import '../../assets/style/mixins/common';

  .bubble-text{
    clear: both;
    width:100%;
    @include disBox();
    dl{
      display:block;
      @include flex1-1();
      dd.text{
        font-size:1.4rem;
        padding:.4rem .8rem;
        border-radius: .6rem;
        margin-top:.3rem;
        position: relative;
        max-width:80%;
        &::after{
          content:" ";
          width: 0;
          height: 0;
          position: absolute;
          // border-top: 1rem solid transparent;
          border-bottom: 1.4rem solid transparent;
          top:0;
        }
        img{
          width:auto;
          height: auto;
          margin-right:0;
          margin-left:0;
          border-radius: 4px;
          max-width: 100%;
          display: inline-block;
          vertical-align: middle;
        }
      }
      dd.date{
        font-size:1.2rem;
        color:$subsidiary-color;
      }
    }
    &.left{
      float:left;
      img{
        margin-right:.8rem;
      }
      dl{
        margin-left:.4rem;
      }
      dd.text{
        background:$write-color;
        float:left;
        &::after{
          left:-.6rem;
          border-right: 1.4rem solid $write-color;
        }
      }
    }
    &.right{
      float:right;
      img{
        margin-left:.8rem;
      }
      dl{
        margin-right:.4rem;
      }
      dd.text{
        color:#fff;
        background: $color;
        float:right;
        &::after{
            right:-.6rem;
            border-left: 1.2rem solid $color;
        }
      }
      dd.date{
        text-align: right;
      }
    }
    img{
      width: 3.6rem;
      height: 3.6rem;
      border-radius: 9999px;
      display: block;
    }
  }
</style>
